package pl.koziolekweb.javafx.twitter;

import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.text.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.ext.swing.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;

/**
 * @author bartlomiejk
 */

class SwingPasswordField extends SwingComponent {
 
    var passwordField: JPasswordField;
 
    public var text:String on replace {
        passwordField.setText(text)
    }
    public var action: function();
    public var columns:Number on replace {
        passwordField.setColumns(columns)
    }
    public var editable:Boolean on replace {
        passwordField.setEditable(editable)
    }
 
    public override function createJComponent():JComponent{
        passwordField = new JPasswordField();
        passwordField.setColumns(columns);
        passwordField.setEditable(editable);
        passwordField.setText(text);
        passwordField.addActionListener(
        ActionListener{
            public override function actionPerformed(e:ActionEvent){
                text = passwordField.getText();
                action();
            }
               
        }
        );
         passwordField.addKeyListener( KeyListener{
             public override function
            keyPressed(keyEvent:KeyEvent) {
 
            }
 
              public override function
            keyTyped(keyEvent:KeyEvent) {
               
            }
 
            public override function
            keyReleased( keyEvent:KeyEvent) {
        
                
               
               if (text != passwordField.getText())
                  text = passwordField.getText()
         
            
            }
 
           
        }
        );
        return passwordField;
    }
}

Stage {
    title: "Application title"
    width: 320
    height: 250
    style: StageStyle.TRANSPARENT
    scene: Scene {
        fill: Color.TRANSPARENT;
        content: Group{
        	content:{
               		[Rectangle {
               		    x: 10,
               			y: 10,
               		    width: 300,
               			height: 230,
               		    fill: Color.BLACK,
               		    stroke: Color.BLACK,
               		    strokeLineCap: StrokeLineCap.ROUND,
               		    arcWidth: 20,
               		    arcHeight: 20
               		},               		
               		SwingTextField {
               		    columns: 10,
               			text: "username",
               		    editable: true
               		    layoutY: 15;
               		    layoutX: 30;
               		},
               		SwingPasswordField {
               			columns: 10,
               		    text: "password",
               		    editable: true
               		    layoutY: 15;
               		    layoutX: 160;
					}]               		
            	}
    	    }
    }
 }
